package com.acyouzi.leetcode.array;

/**
 * 17/9/17 21:36
 *
 * @author sunxu
 */
public class ArrayNesting {
//  https://leetcode.com/problems/array-nesting/description/
  public int arrayNesting(int[] nums) {
    boolean[] flag = new boolean[nums.length];
    int max = 0;
    for (int i = 0; i < nums.length; i++) {
      int index = i;
      int count = 0;
      while (!flag[index]){
        flag[index] = true;
        index = nums[index];
        count++;
      }
      max = Math.max(max,count);
    }
    return max;
  }
}
